package com.test.thread_local.demo2;

public class IfSameThreadLocal {

    public static void main(String[] args) {
        MyService service = new MyService();
        MyThread1 t1 = new MyThread1(service);
        MyThread1 t2 = new MyThread1(service);
        new Thread(t1,"t1").start();
        new Thread(t2,"t2").start();

    }
}
class MyThread1 implements Runnable{
    private MyService myService;

    public MyThread1(MyService myService) {
        this.myService = myService;
    }

    @Override
    public void run() {
        myService.test();
    }
}
class MyThread2 implements Runnable{
    private MyService myService;

    public MyThread2(MyService myService) {
        this.myService = myService;
    }

    @Override
    public void run() {
        myService.test();
    }
}
class MyService{
    private ThreadLocal<String> threadLocal = new ThreadLocal<>();
    public void test(){
        Thread t = Thread.currentThread();
        threadLocal.set("111111");
        threadLocal.set("222222");
        System.out.println("1211221");
    }
}